 var toyApp=angular.module('toyApp');
	toyApp.controller('toylistCtl', [
	'$state',
	'$scope',
	'toyService',
	'broadcastBetweenCtrls',
	function($state,$scope,toyService,broadcastBetweenCtrls){
		$scope.$on('ADD_PRODUCT_WISH',function(){
			querytoylist();
		});
		$scope.toywish=function(toycode){
			toyService('toywish',function(res){
				if(!res.success){
					 return false;
				}else{
					alert('预约成功！');
					$scope.$broadcast('ADD_PRODUCT_WISH');
				
				}},{
		           toycode:toycode,
		           userid:1
				});
			};
		$scope.setquery=function(type,value){
			$scope.querytoytheme='';
			$scope.querytoyage='';
			if(type=='toytheme'){
				$scope.querytoytheme=value;
			}
			else if(type='toyage'){
				$scope.querytoyage=value;
			}
			querytoylist();

		}
		 var querytoylist=function(orderid){
		 	toyService('querytoylist',function(res){
				if(!res.success){
					 return false;
				}
				else{
					$scope.toylist=res.info;
				
				}},{
					theme:$scope.querytoytheme,
 					age:$scope.querytoyage
				});
		};
		$scope.timeStamp=new Date().getTime();
		$scope.$watch('timeStamp',function(){
		querytoylist();
	});
	}]);